<extend name="./_base"/>
<block name="css">

</block>
<block name="header">

</block>
<block name="menu">

</block>
<block name="content">
    <article class="page-container">
        <form class="form form-horizontal" id="form-card">
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>游戏：</label>
                <div class="formControls col-xs-6">
                    <select name="gid" class="input-text">
                        <volist name="GameList" id="vo">
                            <option value="{$vo.id}"
                            <eq name="vo.id" value="$CardData['gid']">selected</eq>
                            >{$vo.name}</option>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>卡号：</label>
                <div class="formControls col-xs-8">

                    <textarea id="cards" style="height: 240px;resize: none" class="input-text" name="cards" placeholder="每行输入一张卡，卡号与密码以空格隔开，单次最高提交500张"></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>过期时间：</label>
                <div class="formControls col-xs-6">
                    <input type="text" class="input-text validate[custom[date]]" value="{$CardData.expire_time}"
                           placeholder="不填写则永不过期" id="expire_time" name="expire_time">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>数量 / 万：</label>
                <div class="formControls col-xs-6">
                    <input type="text" class="input-text validate[required]"
                           value="{$CardData['amount']?$CardData['amount']:10000}" placeholder="" id="amount"
                           name="amount" readonly>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>价格 / 元：</label>
                <div class="formControls col-xs-6">
                    <input type="text" class="input-text validate[required]"
                           value="{$CardData['price']?$CardData['price']:5700}" placeholder="" id="price" name="price"
                           readonly>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-6 col-xs-offset-3">
                    <input class="btn btn-primary btn-block radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>

</block>

<block name="script">
    <script type="text/javascript" src="__PUBLIC__/Lib/laydate/laydate.js"></script>

    <script type="text/javascript">


        $(function () {

            var cards;
            $('#cards').on('change keyup', function (e) {

                var content = $(this).val();
                var lineArray = content.split("\n");
                // console.log(lineArray);
                cards = [];
                $.each(lineArray, function (i, line) {
                    line = line.replace(/[_]+/g, " ");
                    line = line.replace(/[^\w]+/g, " ");
                    line = line.replace(/(^\s*)|(\s*$)/g, "");
                    line = line.split(" ");
                    if(line[1])
                        cards.push({cno: line[0], cpwd: line[1]})
                });
            });

            laydate({
                elem: '#expire_time', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });

            $('#form-card').validationEngine();

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            var flag = true;

            $('#form-card').submit(function () {
                if ($(this).validationEngine('validate')) {
                    if (!flag) {
                        return false;
                    }
                    flag = false;
                    var postData={};
                    $.each($(this).serializeArray(),function (i,item) {
                        if (item['name'] === 'cards'){
                            console.log(cards);
                            postData[item['name']]=cards;
                        }else {
                            postData[item['name']]=item['value'];
                        }
                    });
                    $.post("", postData, function (result) {
                        if (result.status == 1) {
                            layer.alert(result.info, {icon: 6}, function () {
                                parent.location.reload();
                            })
                        } else {
                            layer.alert(result.info, {icon: 5})
                        }
                        flag = true;
                    }, "json");
                }
                return false;
            });
        });
    </script>

</block>
